import { game } from 'cc'
import BTAction from '../../Base/BTAction'
import BlackBoard from '../../BlackBoard'
import { NodeStatus } from '../../Enum'

export default class ActionAttack extends BTAction {
  private duration: number = 2000
  private startTime: number = 0
  constructor(duration: number = 2000) {
    super()
    this.duration = duration
  }

  onStart() {
    super.onStart()
    this.startTime = game.totalTime
    BlackBoard.Instance.hp -= 20
    console.log('ActionAttack onStart')
  }

  onUpdate() {
    if (game.totalTime - this.startTime > this.duration) {
      return NodeStatus.Success
    }

    return NodeStatus.Running
  }

  onEnd() {
    super.onEnd()
    console.log('ActionAttack onEnd')
  }
}
